package sk.marek.barak.client;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.ModifyEvent;


import sk.marek.barak.client.util.OneDayUtil;
import sk.marek.barak.client.util.ValidateData;
import sk.marek.barak.data.Atributes;
import sk.marek.barak.data.InvalidDataException;
import sk.marek.barak.data.NewAnnoucement;


public class NewAnnoucementUI extends Composite {
	private Text text;
	private Map<String, NewAnnoucement> newAnnoucement;
	
	private static java.util.List<String> divisions;
	static{
		divisions = new ArrayList<String>();
		divisions.add("Divison one");
		divisions.add("Division two");
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public NewAnnoucementUI(Composite parent, int style) {
		super(parent, style);
		setLayout(null);
		
		final List list = new List(this, SWT.BORDER);
		list.setFont(SWTResourceManager.getFont("Tahoma", 8, SWT.BOLD));
		list.setBackground(SWTResourceManager.getColor(0, 153, 255));
		list.setForeground(SWTResourceManager.getColor(0, 0, 0));
		list.setItems(new String[] {"NEW", "SAVE", "REMOVE", "FINISH"});
		list.setBounds(0, 0, 62, 268);
		
		Label lblAnnoucementDocNumber = new Label(this, SWT.NONE);
		lblAnnoucementDocNumber.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblAnnoucementDocNumber.setBounds(68, 10, 177, 22);
		lblAnnoucementDocNumber.setText("Annoucement doc. number");
		
		text = new Text(this, SWT.BORDER);
		text.setBounds(267, 13, 97, 19);
		
		Combo combo = new Combo(this, SWT.NONE);
		combo.setBounds(397, 11, 93, 21);
		
		DateTime dateTime = new DateTime(this, SWT.BORDER);
		dateTime.setBounds(355, 48, 135, 21);
		
		Label lblDivision = new Label(this, SWT.NONE);
		lblDivision.setText("Division");
		lblDivision.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblDivision.setBounds(68, 62, 62, 22);
		
		final Combo selectDivision = new Combo(this, SWT.NONE);
		selectDivision.setBounds(150, 62, 93, 21);
		for(String division :divisions){
			selectDivision.add(division);
		}
		
		Button btnFirstLoad = new Button(this, SWT.CHECK);
		btnFirstLoad.setBounds(355, 78, 85, 16);
		btnFirstLoad.setText("First Load");
		
		Label lblAmounth = new Label(this, SWT.NONE);
		lblAmounth.setText("Amounth");
		lblAmounth.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblAmounth.setBounds(134, 107, 62, 22);
		
		Label lblTime = new Label(this, SWT.NONE);
		lblTime.setText("Time");
		lblTime.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblTime.setBounds(355, 107, 62, 22);
		
		Label lblFc = new Label(this, SWT.NONE);
		lblFc.setText("FC");
		lblFc.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblFc.setBounds(68, 135, 23, 22);
		
		Label lblPid = new Label(this, SWT.NONE);
		lblPid.setText("PID");
		lblPid.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblPid.setBounds(68, 163, 23, 22);
		
		Label lblSvp = new Label(this, SWT.NONE);
		lblSvp.setText("SVP");
		lblSvp.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblSvp.setBounds(68, 191, 30, 22);
		
		Label lblConv = new Label(this, SWT.NONE);
		lblConv.setText("CONV");
		lblConv.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
		lblConv.setBounds(68, 219, 34, 22);
		
		final Spinner tFc = new Spinner(this, SWT.BORDER);
		tFc.setVisible(false);
		tFc.setMaximum(1000);
		tFc.setBounds(355, 135, 47, 21);
		
		final Spinner tPid = new Spinner(this, SWT.BORDER);
		tPid.setVisible(false);
		tPid.setMaximum(1000);
		tPid.setBounds(355, 163, 47, 21);
		
		final Spinner tSvp = new Spinner(this, SWT.BORDER);
		tSvp.setVisible(false);
		tSvp.setMaximum(1000);
		tSvp.setBounds(355, 191, 47, 21);
		
		final Spinner tConv = new Spinner(this, SWT.BORDER);
		tConv.setVisible(false);
		tConv.setMaximum(1000);
		tConv.setBounds(355, 220, 47, 21);
		
		
		
		
		final Spinner aFc = new Spinner(this, SWT.BORDER);
		aFc.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(!"0".equals(aFc.getText())){
					tFc.setVisible(true);
					
				}else{
					tFc.setVisible(false);
				}
			}
		});
		aFc.setMaximum(1000);
		aFc.setBounds(150, 134, 47, 21);
		
		final Spinner aPid = new Spinner(this, SWT.BORDER);
		aPid.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if (!"0".equals(aPid.getText()))
					tPid.setVisible(true);
				else
					tPid.setVisible(false);
					
					
			}
		});
		aPid.setMaximum(1000);
		aPid.setBounds(150, 163, 47, 21);
		
		final Spinner aSvp = new Spinner(this, SWT.BORDER);
		
		aSvp.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(!"0".equals(aSvp.getText()))
					tSvp.setVisible(true);
				else
					tSvp.setVisible(false);
					
			}
		});
		aSvp.setMaximum(1000);
		aSvp.setBounds(149, 191, 47, 21);
		
		final Spinner aConv = new Spinner(this, SWT.BORDER);
		aConv.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
			}
		});
		
		aConv.setMaximum(1000);
		aConv.setBounds(150, 219, 47, 21);
		
		list.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				switch(list.getSelectionIndex()){
					case 0: 
					try{
				
					ValidateData.checkAnnoucementDocNumber(text.getText());
					ValidateData.chceckValues(Integer.parseInt(aFc.getText()),Integer.parseInt(tFc.getText()),"Feature code");
					ValidateData.chceckValues(Integer.parseInt(aPid.getText()),Integer.parseInt(tPid.getText()),"Product ID");
					ValidateData.chceckValues(Integer.parseInt(aConv.getText()),Integer.parseInt(tConv.getText()),"Conversion");
					ValidateData.chceckValues(Integer.parseInt(aSvp.getText()),Integer.parseInt(tSvp.getText()),"Service pack");
					
					Atributes atributes = new Atributes();
					atributes.setFcCount(Integer.parseInt(aFc.getText()));
					atributes.setFcTime(Integer.parseInt(tFc.getText()));
					
					atributes.setConvCount(Integer.parseInt(aConv.getText()));
					atributes.setConvTime(Integer.parseInt(tConv.getText()));
					
					atributes.setPidCount(Integer.parseInt(aPid.getText()));
					atributes.setPidTime(Integer.parseInt(tPid.getText()));
					
					atributes.setSvpCount(Integer.parseInt(aSvp.getText()));
					atributes.setSvpTime(Integer.parseInt(tSvp.getText()));
					NewAnnoucement newAnnoucement = new NewAnnoucement();
					
					
					Date date = new Date();
				
				
					
					
					
					}catch(InvalidDataException exception){
						MessageBox message = new MessageBox(getShell());
						message.setText("Error");
						message.setMessage(exception.getMessage());
						message.open();
						};
					break;
				}
			
		}});
		
		
	
		
	}
	
		

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
